import auctionhaus.Role
import auctionhaus.User
import auctionhaus.UserRole
import auctionhaus.Customer

class BootStrap {

	def init = { servletContext ->
		def userRole = Role.findByAuthority('ROLE_USER') ?: new Role(authority: 'ROLE_USER').save(failOnError: true)
		def adminRole = Role.findByAuthority('ROLE_ADMIN') ?: new Role(authority: 'ROLE_ADMIN').save(failOnError: true)
		def adminUser = Customer.findByUsername('admin@auctionhaus.com') ?: new Customer(
				username: 'admin@auctionhaus.com',
				password: ('password'),
				enabled: true).save(failOnError: true)

		if (!adminUser.authorities.contains(adminRole)) {
			UserRole.create adminUser, adminRole
		}
	}
	def destroy = {
	}
}
